<?php

namespace Common\Model;

use Think\Model\RelationModel;

/**
 * 产品模型
 */
class ProductModel extends RelationModel {

    protected $_validate = array(
        array('pname','require','产品名称必须！'), //默认情况下用正则进行验证
    );

    protected $_auto = array(
        array('add_time', 'time', self::MODEL_INSERT, 'function'), // 对add_time字段在添加的时候写入当前时间戳
    );
    protected $_link = array(
        'ProductType' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'ProductType',
            'foreign_key' => 'tid',
            'mapping_name' => 'type',
            'mapping_fields' => 'name',
            'as_fields' => 'name:tname'
        ),
        'Store' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Store',
            'foreign_key' => 'sid',
            'mapping_name' => 'store',
            'mapping_fields' => 'sname,phone',
            'as_fields' => 'sname,phone'
        )
    );

}

?>
